package com.ycc.biz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycc.biz.common.Result;
import com.ycc.biz.pojo.entity.BizOrderDetail;
import com.ycc.biz.service.BizOrderDetailService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: BizOrderDetailController
 * @author: ycl
 * @date: 2025/03/28 17:18:19
 */
@RestController
@RequestMapping("/orderDetail")
@AllArgsConstructor
public class BizOrderDetailController {
    private final BizOrderDetailService orderDetailService;

    @ApiOperation("添加订单明细")
    @PostMapping("/add")
    public Result<Boolean> addOrderDetail(@RequestBody BizOrderDetail orderDetail) {
        return Result.success(orderDetailService.save(orderDetail));
    }

    @ApiOperation("删除订单明细")
    @PostMapping("/delete")
    public Result<Boolean> deleteOrderDetail(@RequestParam Long id) {
        return Result.success(orderDetailService.removeById(id));
    }

    @ApiOperation("更新订单明细")
    @PostMapping("/update")
    public Result<Boolean> updateOrderDetail(@RequestBody BizOrderDetail orderDetail) {
        return Result.success(orderDetailService.updateById(orderDetail));
    }

    @ApiOperation("根据ID查询订单明细")
    @PostMapping("/getById")
    public Result<BizOrderDetail> getOrderDetailById(@RequestParam Long id) {
        return Result.success(orderDetailService.getById(id));
    }

    @ApiOperation("分页查询订单明细")
    @PostMapping("/page")
    public Result<Page<BizOrderDetail>> pageOrderDetails(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.success(orderDetailService.page(new Page<>(pageNum, pageSize)));
    }
}